home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 76 / DVD Actual 1 Marzo 2003.iso / Trial / TurboCAD 7.1 Pro / Data.Cab / F24526_SDKDemoPpg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-10  |  4.8 KB  |  181 lines

  1. // SDKDemoPpg.cpp : Implementation of the CSDKDemoPropPage property page class.
  2.  
  3. #include "stdafx.h"
  4. #include "SDKDemo.h"
  5. #include "SDKDemoPpg.h"
  6.  
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12.  
  13.  
  14. IMPLEMENT_DYNCREATE(CSDKDemoPropPage, COlePropertyPage)
  15.  
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // Message map
  19.  
  20. BEGIN_MESSAGE_MAP(CSDKDemoPropPage, COlePropertyPage)
  21.     //{{AFX_MSG_MAP(CSDKDemoPropPage)
  22.     ON_BN_CLICKED(IDC_FILE_BROWSE, OnFileBrowse)
  23.     ON_BN_CLICKED(IDC_LAYER_REFRESH, OnLayerRefresh)
  24.     ON_BN_CLICKED(IDC_LAYER_SHOW_ALL, OnLayerShowAll)
  25.     //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27.  
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // Initialize class factory and guid
  31.  
  32. IMPLEMENT_OLECREATE_EX(CSDKDemoPropPage, "SDKDEMO.SDKDemoPropPage.1",
  33.     0xa63e6665, 0xc85f, 0x11d0, 0x9b, 0x3b, 0x44, 0x45, 0x53, 0x54, 0, 0)
  34.  
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CSDKDemoPropPage::CSDKDemoPropPageFactory::UpdateRegistry -
  38. // Adds or removes system registry entries for CSDKDemoPropPage
  39.  
  40. BOOL CSDKDemoPropPage::CSDKDemoPropPageFactory::UpdateRegistry(BOOL bRegister)
  41. {
  42.     if (bRegister)
  43.         return AfxOleRegisterPropertyPageClass(AfxGetInstanceHandle(),
  44.             m_clsid, IDS_SDKDEMO_PPG);
  45.     else
  46.         return AfxOleUnregisterClass(m_clsid, NULL);
  47. }
  48.  
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CSDKDemoPropPage::CSDKDemoPropPage - Constructor
  52.  
  53. CSDKDemoPropPage::CSDKDemoPropPage() :
  54.     COlePropertyPage(IDD, IDS_SDKDEMO_PPG_CAPTION)
  55. {
  56.     //{{AFX_DATA_INIT(CSDKDemoPropPage)
  57.     m_strFileName = _T("");
  58.     //}}AFX_DATA_INIT
  59. }
  60.  
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CSDKDemoPropPage::DoDataExchange - Moves data between page and properties
  64.  
  65. void CSDKDemoPropPage::DoDataExchange(CDataExchange* pDX)
  66. {
  67.     //{{AFX_DATA_MAP(CSDKDemoPropPage)
  68.     DDX_Control(pDX, IDC_VISIBLE_LAYERS, m_lbLayers);
  69.     DDP_Text(pDX, IDC_FILE_NAME, m_strFileName, _T("FileName") );
  70.     DDX_Text(pDX, IDC_FILE_NAME, m_strFileName);
  71.     DDV_MaxChars(pDX, m_strFileName, 256);
  72.     //}}AFX_DATA_MAP
  73.  
  74.     CString strLayers;
  75.     DDP_Text(pDX, IDC_VISIBLE_LAYERS, strLayers, _T("HideLayers"));
  76.  
  77.     if (!pDX->m_bSaveAndValidate)
  78.         OnLayerRefresh();
  79.     int nTotalCount = m_lbLayers.GetCount();
  80.     int* rgSel = new int[nTotalCount > 0 ? nTotalCount : 1];
  81.     if (pDX->m_bSaveAndValidate)
  82.     {
  83.         int nSelCount = m_lbLayers.GetSelItems(nTotalCount, rgSel);
  84.         for (int i = 0; i < nSelCount; ++i)
  85.         {
  86.             CString str;
  87.             m_lbLayers.GetText(rgSel[i], str);
  88.             if (!str.IsEmpty())
  89.             {
  90.                 if (!strLayers.IsEmpty())
  91.                     strLayers += "\n";
  92.                 strLayers += str;
  93.             }
  94.         }
  95.     }
  96.     else
  97.     {
  98.         for (int i = 0; i < nTotalCount; ++i)
  99.             m_lbLayers.SetSel(i, FALSE);
  100.         for (i = 0; ; ++i)
  101.         {
  102.             CString str;
  103.             if (!AfxExtractSubString(str, strLayers, i, '\n'))
  104.                 break;
  105.             if (!str.IsEmpty())
  106.             {
  107.                 int nFind = m_lbLayers.FindStringExact(-1, str);
  108.                 if (nFind < 0)
  109.                     nFind = m_lbLayers.AddString(str);
  110.                 if (nFind >= 0)
  111.                     m_lbLayers.SetSel(nFind, TRUE);
  112.             }
  113.         }
  114.     }
  115.     delete [] rgSel;
  116.     DDP_PostProcessing(pDX);
  117. }
  118.  
  119.  
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CSDKDemoPropPage message handlers
  122.  
  123. void CSDKDemoPropPage::OnFileBrowse() 
  124. {
  125.     static TCHAR BASED_CODE szFilter[] = "TurboCAD Drawing Files (*.tcw)|*.tcw|All Files (*.*)|*.*||";
  126.     CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
  127.     if (dlg.DoModal() == IDOK && !dlg.GetPathName().IsEmpty())
  128.     {
  129.         m_strFileName = dlg.GetPathName();
  130.         CDataExchange dx(this, FALSE);
  131.         CDataExchange* pDX = &dx;
  132.         DDX_Text(pDX, IDC_FILE_NAME, m_strFileName);
  133.     }
  134. }
  135.  
  136. void CSDKDemoPropPage::OnLayerRefresh() 
  137. {
  138.     COleDispatchDriver PropDispDriver; 
  139.     ULONG nObjects;
  140.     LPDISPATCH* ppDisp = GetObjectArray(&nObjects);
  141.     for (ULONG i = 0; i < nObjects; i++) 
  142.     { 
  143.         DISPID dwDispID; 
  144.         LPCOLESTR lpOleStr = OLESTR("AllLayers");
  145.         if (SUCCEEDED(ppDisp[i]->GetIDsOfNames(IID_NULL, (LPOLESTR*)&lpOleStr, 1, 0, &dwDispID))) 
  146.         { 
  147.             CString strLayers; 
  148.             PropDispDriver.AttachDispatch(ppDisp[i], FALSE); 
  149.             PropDispDriver.GetProperty(dwDispID, VT_BSTR, &strLayers); 
  150.             PropDispDriver.DetachDispatch();
  151.             for (int j = 0; ; ++j)
  152.             {
  153.                 CString str;
  154.                 if (!AfxExtractSubString(str, strLayers, j, '\n'))
  155.                     break;
  156.                 if (!str.IsEmpty())
  157.                 {
  158.                     int nFind = m_lbLayers.FindStringExact(-1, str);
  159.                     if (nFind < 0)
  160.                         nFind = m_lbLayers.AddString(str);
  161.                 }
  162.             }
  163.         } 
  164.     } 
  165. }
  166.  
  167. void CSDKDemoPropPage::OnLayerShowAll() 
  168. {
  169.     if (m_hWnd != NULL)
  170.     {
  171.         OnLayerRefresh();
  172.         int nCount = m_lbLayers.GetCount();
  173.         for (int i = 0; i < nCount; ++i)
  174.         {
  175.             m_lbLayers.SetSel(i, FALSE);
  176.         }
  177.     }
  178.     SetModifiedFlag();
  179. }
  180.  
  181.